<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\App;

class UserLevelLog extends Base
{
    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\UserLevelLog';

    protected $hasOne = ['user'];

    protected $append = ['type_text', 'area'];

    public function index()
    {
        return $this->setTable();
    }

    public function setTable()
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'uid', 'title' => '会员id', 'templet' => '<span>{{d.user?d.user.id:""}}</span>'])
            ->addRow(['field' => 'code', 'title' => '会员code', 'templet' => '<span>{{d.user?d.user.code:""}}</span>'])
            ->addRow(['field' => 'nickname', 'title' => '会员昵称', 'templet' => '<span>{{d.user?d.user.nickname:""}}</span>'])
            ->addRow(['field' => 'area', 'title' => '地区'])
            ->addRow(['field' => 'type_text', 'title' => '变更类型'])
            ->addRow(['field' => 'before', 'title' => '变更前'])
            ->addRow(['field' => 'after', 'title' => '变更后'])
            ->addRow(['field' => 'intro', 'title' => '说明', 'width' => 300])
            ->addRow(['field' => 'admin_name', 'title' => '后台操作员'])
            ->addRow(['field' => 'create_time', 'title' => '变更时间'])
            //->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 100])
            ->clearTable();

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->setSearch($this->setSearch(), false)
            ->fetch();
    }

    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'])
            ->setSearch(['intro', '说明', 'input', '', '', '', '']);

    }
}